//
//  AppDelegate.m
//  App_6.23
//
//  Created by wanghao on 16/6/23.
//  Copyright © 2016年 wanghao. All rights reserved.
//

#import "AppDelegate.h"
#import "WH_HomeViewController.h"
#import "WH_ListViewController.h"
#import "WH_MeViewController.h"
#import "WH_NewestViewController.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    sleep(.5);
    [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
    
    UMConfigInstance.appKey = mob_key;
    UMConfigInstance.channelId = @"web";
    [MobClick startWithConfigure:UMConfigInstance];//配置以上参数后调用此方法初始化SDK！
    [MobClick setAppVersion:XcodeAppVersion];

    
    [self appProgram];
    [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction : @"YOUR_CLIENT_ID_FOR_PRODUCTION",
                                                           PayPalEnvironmentSandbox : @"ASTYe6YWzonUMkOMv_5HaXvY9_sz5z5v3Sr4MV7RAW3Siqk_8uplSJOalZj8HzWXTaXaCCuVqi2adqic"}];
    
    

    return YES;
}

- (void)appProgram{
    [[LS_ListDataBase shareDataBase] openDB];
    //[[LS_ListDataBase shareDataBase] createTable];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    WH_HomeViewController *home = [[WH_HomeViewController alloc] init];
    UINavigationController *navCH = [[UINavigationController alloc] initWithRootViewController:home];
    
    WH_ListViewController *list = [[WH_ListViewController alloc] init];
    UINavigationController *navCL = [[UINavigationController alloc] initWithRootViewController:list];
    
    WH_MeViewController *mine = [[WH_MeViewController alloc] init];
    UINavigationController *navCM = [[UINavigationController alloc] initWithRootViewController:mine];
    
    WH_NewestViewController *newest = [[WH_NewestViewController alloc] init];
    UINavigationController *navCN = [[UINavigationController alloc] initWithRootViewController:newest];
    
    self.tabbarMain = [[UITabBarController alloc] init];
    _tabbarMain.delegate = self;
    _tabbarMain.viewControllers = [NSArray arrayWithObjects:navCH, navCN, navCL, navCM, nil];
    
    navCH.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"夺宝" image:[UIImage imageNamed:@"夺宝"] tag:10000];
    navCN.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"最新揭晓" image:[UIImage imageNamed:@"最新揭晓"] tag:10001];
    navCL.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"清单" image:[UIImage imageNamed:@"清单"] tag:10002];
    navCM.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"我"] tag:10003];
    self.window.rootViewController = _tabbarMain;
    _tabbarMain.tabBar.tintColor = [UIColor redColor];
    //_tabbarMain.tabBar.translucent = NO;

    
}


- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    
    NSLog(@"Calling Application Bundle ID: %@", sourceApplication);
    return  [[FBSDKApplicationDelegate sharedInstance] application:application
                                                           openURL:url
                                                 sourceApplication:sourceApplication
                                                        annotation:annotation];
    
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [FBSDKAppEvents activateApp];

}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
